//
//  ST_VideoBubbleView.swift
//  BTVideo
//
//  Created by DouLei on 2019/9/29.
//  Copyright © 2019 DouLei. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift
import HandyJSON

class ST_VideoBubbleView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(bubble_back_image_view)
        bubble_back_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        self.addSubview(iconView)
        self.addSubview(titleLabel)
        self.addSubview(sub_title_label)
        
        iconView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(17)
            make.top.equalToSuperview().offset(23)
            make.width.height.equalTo(34)
        }
        
        
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(20)
            make.left.equalTo(iconView.snp.right).offset(2)
        }
        
        
        sub_title_label.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(3)
            make.left.equalTo(titleLabel)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK: - Properties
    fileprivate lazy var iconView:UIImageView = {
        let control = UIImageView()
        return control
    }()
    
    fileprivate lazy var bubble_back_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("IndexItem_bg_提示bgL")
        control.contentMode = UIView.ContentMode.scaleToFill
        return control
    }()
    
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.textColor = Color.init(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)
        return control
    }()
    
    fileprivate lazy var sub_title_label:UILabel = {
        let control = UILabel.init()
        control.textColor = Color.init(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        return control
    }()
    
//    MARK: - Bind Model
    fileprivate var bubble = ST_BubbleLogicModel(){
        
        didSet{
            
            
            iconView.pin_setImage(from: bubble.icon.compress_image().url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
            titleLabel.text = bubble.title
            sub_title_label.text = bubble.words
            
        }
    }
    
//    绑定数据返回宽度
    func bind_model(_ model:ST_BubbleLogicModel)->CGFloat{
        
        self.bubble = model
        
        let titleWidth = bubble.title.width(withConstrainedHeight: 100, font: titleLabel.font)
        
        let subtitleWidth = bubble.words.width(withConstrainedHeight: 100, font: sub_title_label.font)
        
        if subtitleWidth > titleWidth{
            return subtitleWidth + 104
        }else{
            return titleWidth + 104
        }
    }
    
}



class ST_VideoRightBubbleView: UIView {
    
    static let height = 66.cgFloat
    
    static let width = 250.cgFloat
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(bubble_back_image_view)
        bubble_back_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        self.addSubview(titleLabel)
        
        
        titleLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(13)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK: - Properties
    fileprivate lazy var iconView:UIImageView = {
        let control = UIImageView()
        return control
    }()
    
    fileprivate lazy var bubble_back_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("IndexItem_bg_提示bgR")
        control.contentMode = UIView.ContentMode.scaleToFill
        return control
    }()
    
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.textColor = Color.init(hexString: "#333333")
        control.text = "💖 💖 哇哦！有人喜欢了你哦！!"
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)
        return control
    }()
}


class ST_SuperHotBubbleView:UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(bubble_back_image_view)
        bubble_back_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        self.addSubview(titleLabel)
      
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-2)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK: - Properties
    
    fileprivate lazy var bubble_back_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("IndexItem_img_已推给")
        control.contentMode = UIView.ContentMode.scaleToFill
        return control
    }()
    
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.textColor = Color.white
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)
        return control
    }()
    
    
//    MARK: - Bind Model
  
    
//    绑定数据返回宽度
    func bind_model(introductionNumber:Int)->CGFloat{
        
        
        let introductionStr = "已推给 "+introductionNumber.string+" 人"
        
        let titleWidth = introductionStr.width(withConstrainedHeight: 100, font: titleLabel.font)
        
        titleLabel.text = introductionStr
        
        return titleWidth+44
    }
    
}




//MARK: - Bubble logic Model
class ST_BubbleLogicModel: HandyJSON {
    
    var id = ""
    var title = ""
    var flip_cnt = 0
    var icon = ""
    var words = ""
    
    required init() {
    }
    
}
